package com.hnevc.stringbuffer;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.Scanner;

public class RandomCallNameSystem {
	private ArrayList<String> nameList;
	public ArrayList<String> getNameList() {
		return nameList;
	}
	public void initData(){
		nameList = new ArrayList<>();
		File file = new File("data.txt");
		Scanner scanner = null;
		try {
			scanner = new Scanner(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String s = scanner.next();
		String[] names = s.split("-");
		for(int i=0;i<names.length;i++){
			nameList.add(names[i]);
		}
		System.out.println("initDataOK");
	}
	public void showNames(){
		Iterator<String> it = nameList.iterator();
		while(it.hasNext()){
			String name = it.next();
			System.out.print(name+ " ");
		}
		System.out.println("");
	}
	
	public String callName(){
		Random random = new Random();
		int number = random.nextInt(nameList.size());
		return nameList.get(number);
		
		
	}
}
